<?php 

/**
* 
*/
class HtmlController extends AuthController
{
	function __init()
	{
		define('__TEMPLATE__',__ROOT__.'/Template/'.C('WEBSTYLE'));//模板中使用
		
	}
	//生产静态首页
	public function createIndex()
	{
		if (IS_POST) {
			$status=$this->createHtml('index.html','./','template/'.C('WEBSTYLE').'/index.html');
			if ($status) {
				$this->success('生成静态成功','createIndex');
			}else{
				$this->error('生成失败','createIndex');
			}
		}else{
			$this->display();
		}
	}

	//生成静态栏目
	public function createCategory()
	{
		if (IS_POST) {
			$data=M('category')->all();
			foreach ($data as $cat) {
				$_REQUEST['cid']=$_GET['cid']=$cat['cid'];
				$htmlDir='cc/'.$cat['html_dir'].'/';
				$this->assign('data',$cat);
				// 生成首页为获取Page::$staticUrl 
				$this->createHtml('index.html',$htmlDir,'Template/'.C('WEBSTYLE').'/'.$cat['list_tpl']);
				for ($page=1; $page <=Page::$staticTotalPage ; $page++) { 
					$_GET['page']=$page;
					//分页链接的url  
					Page::$staticUrl=__ROOT__.'/'.$htmlDir.'{page}.html';
					$this->createHtml($page.'.html',$htmlDir,'Template/'.C('WEBSTYLE').'/'.$cat['list_tpl']);
				}
				/**
			       * 生成index.html,没有办法设置Page::$staticUrl
			       * 造成页码链接不对,还是使用动态
			       * 但是1.html就没有问题
			       * 1.html就是index.html  1.html 覆盖index.html
			       */
				copy($htmlDir.'1.html', $htmlDir.'index.html');
			}
			$this->success('生成静态成功','createCategory');	
		}else{
			$this->display();
		}	
	}

	//生成静态内容
	public function createContent()
	{
		if (IS_POST) {
			$data=K('content')->all();
			foreach ($data as $con) {
       			$this->assign('data2',$con);
       			//按规则替换获得文件地址
       			$search=array('{y}','{m}','{d}','{aid}');
       			$data=getdate($con['addtime']);
       			$replace=array($data['year'],$data['mon'],$data['mday'],$con['aid']);
       			$path='cc/'.$con['html_dir'].'/'.str_replace($search, $replace,$con['arc_html_rule']);
       			$this->createHtml(basename($path),dirname($path).'/','Template/'.C('WEBSTYLE').'/'.$con['content_tpl']);
			}
			$this->success('生成静态成功','createContent');
		}else{
			$this->display();
		}
	}


}

 ?>